<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>面向对象</title>
		<style>
			#div1 input {
				background: cornflowerblue;
				width: 60px;
				height: 30px;
				border: 0;
				margin: 2px;
			}
			
			#div1 .active {
				background: yellow;
			}
			
			#div1 div {
				width: 200px;
				height: 200px;
				line-height: 200px;
				background: #CCC;
				display: none;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<input class="active" type="button" value="1" />
			<input type="button" value="2" />
			<input type="button" value="3" />
			
			<div style="display:block;">1</div>
			<div>2</div>
			<div>3</div>
		</div>
	</body>
	<script>
		window.onload = function() {
			var oDiv = document.getElementById('div1');
			var aBtn = oDiv.getElementsByTagName('input');
			var aDiv = oDiv.getElementsByTagName('div');
			var i = 0;

			for(i = 0; i < aBtn.length; i++) {
				aBtn[i].index = i;
				aBtn[i].onclick = function() {
					for(i = 0; i < aBtn.length; i++) {
						aBtn[i].className = '';
						aDiv[i].style.display = 'none';
					}
					this.className = 'active';
					aDiv[this.index].style.display = 'block';
				};
			}
		};
	</script>
</html>